Ext.define('MyApp.util.Helper', {
	singleton: true,

	/**
	 args: {
		key1: value1,
		key2: value2
	 }
	 */
	invoke: function (api, args, options) {
		Ext.Viewport.setMasked(true)
		Ext.Ajax.request({ 
			url: Config.host + api,
			params: Ext.apply({
				'_token': localStorage.token,
				'_appId': 'myapp'
			}, args),
			success: function(response, operation){
				var result = Ext.decode(response.responseText);
				if(options.success)
					options.success(result);
			},
			failure: function(response, operation){
				var msg = response.responseText || response.statusText;
                if(response.status == '0'){
                    console.log('communication failure');
                }
                else if(response.status == '440'){ //登录信息失效
                    Ext.Msg.alert('登录信息失效')
                    //Pnt.needLogin();
                }
                else{
                    if(options.failure)
						options.failure(msg, response.status);
                }
			},
			callback: function(operation, success, response){
				Ext.Viewport.setMasked(false);
                if(options.callback)
					options.callback(success, response);
			}
		});
	}
});